'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute i'''
n=0
str =""
a=[]
for i in range(100,1000):
    for y in range(2,i):
        if i%y==0:
            break
    else:
        a.append(i)
#print(a)
s0 = "zero"
s1 = "one"
s2 = "two"
s3 = "three"
s4 = "four"
s5 = "five"
s6 = "six"
s7 = "seven"
s8 = "eight"
s9 = "nine"
s10 = input().split()

for i in range(len(s10)):
    if s10[i]==s0:
        #print(0, end="")
        str =str+"0"
        
    if s10[i]==s1:
        #print(1, end="")
        str =str+"1"
    if s10[i]==s2:
        #print(2, end="")
         str =str+"2"
    if s10[i]==s3:
       # print(3, end="")
        str =str+"3"
    if s10[i]==s4:
        #print(4, end="")
         str =str+"4"
    if s10[i]==s5:
        #print(5, end="")
         str =str+"5"
    if s10[i]==s6:
       # print(6, end="")
         str =str+"6"
    if s10[i]==s7:
       # print(7, end="")
         str =str+"7"
    if s10[i]==s8:
        #print(8, end="")
         str =str+"8"
    if s10[i]==s9:
       # print(9, end="")
         str =str+"9"
if str != "":
    n=int(str)
if n==0 or n<=99 or n>=1000:
    print("Wrong input")
else:
    if n > 997:
        print("997")
    else:
        if n in a:
            print(n)
        else:
            for i in range(len(a)):
                if a[i]>n:
                    k=i
                if a[i]<n:
                    k1=i
            if abs(a[k1]-n)>abs(a[k1+1]-n):
                print(a[k1+1])
            else:
                print(a[k1])
            
    
